package com.suneee.cloud.group.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.suneee.base.util.ContextHelper;
import com.suneee.cloud.group.dao.ShopAdminDao;
import com.suneee.cloud.group.entity.ShopAdminEntity;
import com.suneee.core.util.StringUtils;
import com.suneee.orm.GenericDao;

@Repository("shopAdminDao")
public class ShopAdminDaoImpl extends GenericDao<ShopAdminEntity, Integer> implements ShopAdminDao {

	@Override
	public void insertShopAdminInfo(List<ShopAdminEntity> shopAdminEty) 
	{
		String shopId = shopAdminEty.get(0).getShopId();
		String adminId = shopAdminEty.get(0).getAdminId();
		
		//授权店铺前先将店铺授权信息全部删除后。 再重新授权。 
		Object [] args = new Object[2];
		args[0] = shopId;
		args[1] = ContextHelper.getCurrentLoginInfo().getEnterpriseCode();
		this.deleteWhere("shop_id = ? and admin_id != (SELECT admin_id FROM t_administrator  WHERE enterprise_code = ? AND admin = 1)", args);
		
		//若adminId为空表示。 清空改店铺所有授权。
		if(!StringUtils.isEmpty(adminId))
		{
			this.insert(shopAdminEty);
		}
	}
    
	@Override
	public void inserSuperAdminfinfo(String shopId, String adminId) 
	{
		ShopAdminEntity shopAdminEty = new ShopAdminEntity();
		shopAdminEty.setAdminId(adminId);
		shopAdminEty.setShopId(shopId);
		this.insert(shopAdminEty);
	}

}
